package week1.day5;

/**
 * @Author fengzihao
 * @Date 2024-04-19 19:46
 */
public class ItemTest {
    public static void main(String[] args) {
        Item item1 = new Item();
        item1.name = "Samsung Galaxy S21";
        item1.type = "手机";
        item1.price = 8000;
        Item item2 = new Item();
        item2.name = "海尔冰箱";
        item2.type = "家具";
        item2.price = 3000;
        Item item3 = new Item();
        item3.name = "海飞丝洗发水";
        item3.type = "日用品";
        item3.price = 30;
        int returnMoney1 = item1.sell(9000);
        int returnMoney2 = item2.sell(2000);
        int returnMoney3 = item3.sell(30);
        System.out.println("returnMoney1 = " + returnMoney1);
        System.out.println("returnMoney2 = " + returnMoney2);
        System.out.println("returnMoney3 = " + returnMoney3);

    }
}
class Item{
    public String name;
    public int price;
    public String type;

    public int sell(int money){
        if (price<=money){
            System.out.println(name+"物品被卖出");
            return money-price;
        }else {
            System.out.println("金钱不足，购买失败");
            return -1;
        }
    }
}
